import pygame

from constants import WHITE

def load_image(path, scale=1.0):
    image = pygame.image.load(path).convert_alpha()
    # 可选：按比例缩放图片
    size = image.get_size()
    size = (int(size[0] * scale), int(size[1] * scale))
    return pygame.transform.scale(image, size)

def draw_text(surf, text, font, size, x, y):
    text_surface = font.render(text, True, WHITE)
    surf.blit(text_surface, (x, y))

def draw_health_bar(surface, x, y, health, max_health):
    BAR_LENGTH = 100
    BAR_HEIGHT = 10
    fill = (health / max_health) * BAR_LENGTH
    outline_rect = pygame.Rect(x, y, BAR_LENGTH, BAR_HEIGHT)
    fill_rect = pygame.Rect(x, y, fill, BAR_HEIGHT)
    pygame.draw.rect(surface, (0, 255, 0), fill_rect)  # 绿色血条
    pygame.draw.rect(surface, (255, 255, 255), outline_rect, 2)  # 白色边框